<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/private-blog/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/private-blog/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/private-blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/private-blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/private-blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/private-blog/images/yy.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/private-blog/images/icon/yy32.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/private-blog/images/icon/yy16.jpg?v=5.1.4">


  <link rel="mask-icon" href="/private-blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java,MybatisPlus," />










<meta name="description" content="从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。">
<meta name="keywords" content="Java,MybatisPlus">
<meta property="og:type" content="article">
<meta property="og:title" content="MP多模块代码生成器模板">
<meta property="og:url" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;2020&#x2F;05&#x2F;17&#x2F;MP%E5%A4%9A%E6%A8%A1%E5%9D%97%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E5%99%A8%E6%A8%A1%E6%9D%BF&#x2F;index.html">
<meta property="og:site_name" content="Culaccino&#39;s blog">
<meta property="og:description" content="从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;Java&#x2F;1.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;Java&#x2F;2.png">
<meta property="og:updated_time" content="2021-09-30T03:32:24.399Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;Java&#x2F;1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/private-blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://zy0912.gitee.io/private-blog/2020/05/17/MP多模块代码生成器模板/"/>





  <title>MP多模块代码生成器模板 | Culaccino's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/private-blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Culaccino's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Nothing is impossible！！</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/private-blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/private-blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/private-blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/private-blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zy0912.gitee.io/private-blog/private-blog/2020/05/17/MP%E5%A4%9A%E6%A8%A1%E5%9D%97%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E5%99%A8%E6%A8%A1%E6%9D%BF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Culaccino">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/private-blog/images/yy.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Culaccino's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">MP多模块代码生成器模板</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-17T10:34:20+08:00">
                2020-05-17
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/private-blog/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/private-blog/categories/Java/MybatisPlus/" itemprop="url" rel="index">
                    <span itemprop="name">MybatisPlus</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本页总阅读数<i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。"><a href="#从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。" class="headerlink" title="从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。"></a>从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。</h4><a id="more"></a>

<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.studio.utils;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.DbType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.toolkit.StringPool;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.toolkit.StringUtils;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.AutoGenerator;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.InjectionConfig;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.*;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.po.TableInfo;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.sql.Driver;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;h3&gt;mpgenerator&lt;/h3&gt;</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;&lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> : zhengyue</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> : 2020-03-13 17:13</span></span><br><span class="line"><span class="comment"> **/</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CodeGenerator</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">scanner</span><span class="params">(String tip)</span> </span>&#123;</span><br><span class="line">        Scanner scanner = <span class="keyword">new</span> Scanner(System.in);</span><br><span class="line">        StringBuilder help = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">        help.append(<span class="string">"请输入"</span> + tip + <span class="string">"："</span>);</span><br><span class="line">        System.out.println(help.toString());</span><br><span class="line">        <span class="keyword">if</span> (scanner.hasNext()) &#123;</span><br><span class="line">            String ipt = scanner.next();</span><br><span class="line">            <span class="keyword">if</span> (StringUtils.isNotEmpty(ipt)) &#123;</span><br><span class="line">                <span class="keyword">return</span> ipt;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> MybatisPlusException(<span class="string">"请输入正确的"</span> + tip + <span class="string">"！"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"><span class="comment">//      String [] tableNames = new String[]&#123;"cms_user"&#125;;</span></span><br><span class="line">        String[] tableNames = scanner(<span class="string">"表名，多个英文逗号分割"</span>).split(<span class="string">","</span>);</span><br><span class="line"></span><br><span class="line">        String [] modules = <span class="keyword">new</span> String[]&#123;<span class="string">"studio_pojo"</span>, <span class="string">"studio_dao"</span>, <span class="string">"studio_service"</span>, <span class="string">"studio_controller"</span>&#125;;<span class="comment">//项目模块名，需自定义</span></span><br><span class="line">        <span class="keyword">for</span> (String <span class="keyword">module</span> : modules) &#123;</span><br><span class="line">            moduleGenerator(<span class="keyword">module</span>,tableNames);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">moduleGenerator</span><span class="params">(String <span class="keyword">module</span>,String [] tableNames)</span></span>&#123;</span><br><span class="line"></span><br><span class="line">        GlobalConfig globalConfig = getGlobalConfig(<span class="keyword">module</span>);<span class="comment">// 全局配置</span></span><br><span class="line"></span><br><span class="line">        DataSourceConfig dataSourceConfig = getDataSourceConfig();<span class="comment">// 数据源配置</span></span><br><span class="line"></span><br><span class="line">        PackageConfig packageConfig = getPackageConfig(<span class="keyword">module</span>);<span class="comment">// 包配置</span></span><br><span class="line"></span><br><span class="line">        StrategyConfig strategyConfig = getStrategyConfig(tableNames);<span class="comment">// 策略配置</span></span><br><span class="line"></span><br><span class="line">        TemplateConfig templateConfig = getTemplateConfig(<span class="keyword">module</span>);<span class="comment">// 配置模板</span></span><br><span class="line"></span><br><span class="line">        InjectionConfig cfgConfig = getCfgConfig(); <span class="comment">//自定义导出设置</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">new</span> AutoGenerator()</span><br><span class="line">                .setGlobalConfig(globalConfig)</span><br><span class="line">                .setDataSource(dataSourceConfig)</span><br><span class="line">                .setPackageInfo(packageConfig)</span><br><span class="line">                .setStrategy(strategyConfig)</span><br><span class="line">                .setTemplate(templateConfig)</span><br><span class="line">                .setCfg(cfgConfig)</span><br><span class="line">                .execute();</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> InjectionConfig <span class="title">getCfgConfig</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        InjectionConfig cfg = <span class="keyword">new</span> InjectionConfig() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">initMap</span><span class="params">()</span> </span>&#123;</span><br><span class="line">                <span class="comment">// to do nothing</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        String projectPath = System.getProperty(<span class="string">"user.dir"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 如果模板引擎是 freemarker</span></span><br><span class="line"><span class="comment">//        String templatePath = "/templates/mapper.xml.ftl";</span></span><br><span class="line">        <span class="comment">// 如果模板引擎是 velocity</span></span><br><span class="line">         String templatePath = <span class="string">"/templates/mapper.xml.vm"</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 自定义输出配置</span></span><br><span class="line">        List&lt;FileOutConfig&gt; focList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="comment">// 自定义配置会被优先输出</span></span><br><span class="line">        focList.add(<span class="keyword">new</span> FileOutConfig(templatePath) &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> String <span class="title">outputFile</span><span class="params">(TableInfo tableInfo)</span> </span>&#123;</span><br><span class="line">                <span class="comment">// 自定义输出文件名 ， 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化！！</span></span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">new</span> File(<span class="string">"studio_dao"</span>).getAbsolutePath()+ <span class="string">"/src/main/resources/mapper/"</span> + tableInfo.getEntityName()</span><br><span class="line">                        + <span class="string">"Mapper"</span> + StringPool.DOT_XML;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        cfg.setFileOutConfigList(focList);</span><br><span class="line">        <span class="keyword">return</span> cfg;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> TemplateConfig <span class="title">getTemplateConfig</span><span class="params">(String <span class="keyword">module</span>)</span> </span>&#123;</span><br><span class="line">        TemplateConfig templateConfig = <span class="keyword">new</span> TemplateConfig();</span><br><span class="line">        <span class="comment">//studio_pojo", "studio_dao", "studio_service", "studio_controller</span></span><br><span class="line">        <span class="keyword">if</span> (<span class="string">"studio_pojo"</span>.equals(<span class="keyword">module</span>))&#123;</span><br><span class="line">            templateConfig.setEntity(<span class="keyword">new</span> TemplateConfig().getEntity(<span class="keyword">false</span>))</span><br><span class="line">                    .setMapper(<span class="keyword">null</span>)<span class="comment">//mapper模板</span></span><br><span class="line">                    .setXml(<span class="keyword">null</span>)</span><br><span class="line">                    .setService(<span class="keyword">null</span>)</span><br><span class="line">                    .setServiceImpl(<span class="keyword">null</span>)</span><br><span class="line">                    .setController(<span class="keyword">null</span>);<span class="comment">//service模块不生成controller代码</span></span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (<span class="string">"studio_dao"</span>.equals(<span class="keyword">module</span>))&#123;<span class="comment">//web模块只生成controller代码</span></span><br><span class="line">            templateConfig.setEntity(<span class="keyword">null</span>)</span><br><span class="line">                    .setMapper(<span class="keyword">new</span> TemplateConfig().getMapper())</span><br><span class="line">                    .setXml(<span class="keyword">null</span>)</span><br><span class="line">                    .setService(<span class="keyword">null</span>)</span><br><span class="line">                    .setServiceImpl(<span class="keyword">null</span>)</span><br><span class="line">                    .setController(<span class="keyword">null</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (<span class="string">"studio_service"</span>.equals(<span class="keyword">module</span>))&#123;<span class="comment">//web模块只生成controller代码</span></span><br><span class="line">            templateConfig.setEntity(<span class="keyword">null</span>)</span><br><span class="line">                    .setMapper(<span class="keyword">null</span>)</span><br><span class="line">                    .setXml(<span class="keyword">null</span>)</span><br><span class="line">                    .setService(<span class="keyword">new</span> TemplateConfig().getService())</span><br><span class="line">                    .setServiceImpl(<span class="keyword">new</span> TemplateConfig().getServiceImpl())</span><br><span class="line">                    .setController(<span class="keyword">null</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (<span class="string">"studio_controller"</span>.equals(<span class="keyword">module</span>))&#123;<span class="comment">//web模块只生成controller代码</span></span><br><span class="line">            templateConfig.setEntity(<span class="keyword">null</span>)</span><br><span class="line">                    .setMapper(<span class="keyword">null</span>)</span><br><span class="line">                    .setXml(<span class="keyword">null</span>)</span><br><span class="line">                    .setService(<span class="keyword">null</span>)</span><br><span class="line">                    .setServiceImpl(<span class="keyword">null</span>)</span><br><span class="line">                    .setController(<span class="keyword">new</span> TemplateConfig().getController());</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> IllegalArgumentException(<span class="string">"参数匹配错误，请检查"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> templateConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> StrategyConfig <span class="title">getStrategyConfig</span><span class="params">(String[] tableNames)</span> </span>&#123;</span><br><span class="line">        StrategyConfig strategyConfig = <span class="keyword">new</span> StrategyConfig();</span><br><span class="line">        strategyConfig</span><br><span class="line">                <span class="comment">//驼峰命名</span></span><br><span class="line">                .setCapitalMode(<span class="keyword">true</span>)</span><br><span class="line">                <span class="comment">//lombok</span></span><br><span class="line">                .setEntityLombokModel(<span class="keyword">true</span>) </span><br><span class="line">                <span class="comment">//restful</span></span><br><span class="line">                .setRestControllerStyle(<span class="keyword">true</span>) </span><br><span class="line">                .setNaming(NamingStrategy.underline_to_camel)</span><br><span class="line">                .setColumnNaming(NamingStrategy.underline_to_camel)</span><br><span class="line">                <span class="comment">//继承父类</span></span><br><span class="line">                .setSuperEntityClass(<span class="string">"com.studio.entity.BaseEntity"</span>)</span><br><span class="line">                <span class="comment">//排除父类的属性</span></span><br><span class="line">                .setSuperEntityColumns(<span class="keyword">new</span> String[]&#123;<span class="string">"id"</span>, <span class="string">"create_id"</span>, <span class="string">"update_id"</span>, <span class="string">"create_time"</span>, <span class="string">"update_time"</span>, <span class="string">"is_del"</span>&#125;)</span><br><span class="line">                .setInclude(tableNames);</span><br><span class="line">        <span class="keyword">return</span> strategyConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> PackageConfig <span class="title">getPackageConfig</span><span class="params">(String <span class="keyword">module</span>)</span> </span>&#123;</span><br><span class="line">        PackageConfig packageConfig = <span class="keyword">new</span> PackageConfig();</span><br><span class="line">        String packageName = <span class="string">"com.studio"</span>;<span class="comment">//不同模块 代码生成具体路径自定义指定</span></span><br><span class="line">        <span class="comment">//studio_pojo", "studio_dao", "studio_service", "studio_controller</span></span><br><span class="line">        packageConfig.setParent(packageName)</span><br><span class="line">                .setEntity(<span class="string">"entity"</span>)</span><br><span class="line">                .setMapper(<span class="string">"mapper"</span>)</span><br><span class="line">                .setService(<span class="string">"service"</span>)</span><br><span class="line">                .setController(<span class="string">"controller"</span>);</span><br><span class="line">        <span class="keyword">return</span> packageConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> DataSourceConfig <span class="title">getDataSourceConfig</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        String dbUrl = <span class="string">"jdbc:mysql://*.*.*.*:3306/software_studio?useSSL=false&amp;serverTimezone=GMT%2B8&amp;characterEncoding=utf8&amp;allowPublicKeyRetrieval=true"</span>;</span><br><span class="line">        DataSourceConfig dataSourceConfig = <span class="keyword">new</span> DataSourceConfig();</span><br><span class="line">        dataSourceConfig.setDbType(DbType.MYSQL)</span><br><span class="line">                .setDriverName(Driver.class.getName())</span><br><span class="line">                .setUsername(<span class="string">"root"</span>)</span><br><span class="line">                .setPassword(<span class="string">"123456"</span>)</span><br><span class="line">                .setUrl(dbUrl);</span><br><span class="line">        <span class="keyword">return</span> dataSourceConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> GlobalConfig <span class="title">getGlobalConfig</span><span class="params">(String <span class="keyword">module</span>)</span> </span>&#123;</span><br><span class="line">        GlobalConfig globalConfig = <span class="keyword">new</span> GlobalConfig();</span><br><span class="line">        String projectPath = System.getProperty(<span class="string">"user.dir"</span>);</span><br><span class="line">        globalConfig.setOpen(<span class="keyword">false</span>)<span class="comment">//new File(module).getAbsolutePath()得到模块根目录路径，因事Maven项目，代码指定路径自定义调整</span></span><br><span class="line">                .setOutputDir(<span class="keyword">new</span> File(<span class="keyword">module</span>).getAbsolutePath()+<span class="string">"/src/main/java"</span>) <span class="comment">//生成文件的输出目录</span></span><br><span class="line">                .setFileOverride(<span class="keyword">false</span>)<span class="comment">//是否覆盖已有文件</span></span><br><span class="line">                .setActiveRecord(<span class="keyword">false</span>)</span><br><span class="line">                .setIdType(IdType.ID_WORKER)</span><br><span class="line">                .setAuthor(<span class="string">"zhengyue"</span>);</span><br><span class="line">        <span class="keyword">return</span> globalConfig;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="效果图展示"><a href="#效果图展示" class="headerlink" title="效果图展示"></a>效果图展示</h2><p><img src="/private-blog/images/Java/1.png" alt="Yoyou"><br><img src="/private-blog/images/Java/2.png" alt="Yoyou"></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>如果你觉得有帮助，慷慨如你，可以扫描下面的二维码赞赏一下</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/yy.jpg" alt="Culaccino 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/yy.jpg" alt="Culaccino 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/private-blog/tags/Java/" rel="tag"># Java</a>
          
            <a href="/private-blog/tags/MybatisPlus/" rel="tag"># MybatisPlus</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/private-blog/2020/05/16/Docker%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4%EF%BC%88%E4%BA%8C%EF%BC%89/" rel="next" title="Docker基本命令（二）">
                <i class="fa fa-chevron-left"></i> Docker基本命令（二）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/private-blog/2020/05/18/SpringBoot-Webmagic-Redis%E5%AE%9A%E6%97%B6%E7%88%AC%E5%8F%96%E6%95%B0%E6%8D%AE/" rel="prev" title="SpringBoot+Webmagic+Redis+Docker定时爬取数据">
                SpringBoot+Webmagic+Redis+Docker定时爬取数据 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/private-blog/images/yy.jpg"
                alt="Culaccino" />
            
              <p class="site-author-name" itemprop="name">Culaccino</p>
              <p class="site-description motion-element" itemprop="description">A glass with a cold drink left a round watermark on the table.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/private-blog/archives">
              
                  <span class="site-state-item-count">40</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/private-blog/categories/index.html">
                  <span class="site-state-item-count">32</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/private-blog/tags/index.html">
                  <span class="site-state-item-count">38</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhengyue12" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mail.qq.com/" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://info52.top" title="山有木兮" target="_blank">山有木兮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://dianzihut.com/" title="RE-Empire" target="_blank">RE-Empire</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。"><span class="nav-number">1.</span> <span class="nav-text">从正式进入项目组到接手练习做项目，一直想写一个多模块的代码生成器，方便组内其他成员去自动生成三层架构和实体类等代码，避免重复繁琐的操作。又因为这几天改Bug改到自闭，一直没有时间将其实践起来。因为今天是周末所以早早就起来，结合官网的单模块代码生成器，以及一上午仅仅找到一篇类似的博客进行改写，完成了多模块代码生成的模板。以下直接放代码，记录一下，方便以后工作直接套用。</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#代码"><span class="nav-number"></span> <span class="nav-text">代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#效果图展示"><span class="nav-number"></span> <span class="nav-text">效果图展示</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 &mdash; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Culaccino</span>

  
</div>

<!--
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>


-->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js""></script>

  
    <span class="site-uv">
      本站访问数 <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量 <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/private-blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/private-blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/private-blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/private-blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/private-blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/private-blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/private-blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/private-blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/private-blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
